﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Diagnostics;
using OracleTools.Core;

namespace OracleTools.OracleHomeSelector
{
	/// <summary>
	/// Interaction logic for NlsListForm.xaml
	/// </summary>
	public partial class NlsListForm : Window
	{

        SavedNlsLangs m_savedNlsLangs;
        OraMaster m_master;

		public NlsListForm(SavedNlsLangs savedNlsLangs, OraMaster master)
		{
			this.InitializeComponent();

            m_savedNlsLangs = savedNlsLangs;
            m_master = master;

            StringBuilder sb = new StringBuilder();
            savedNlsLangs.NlsLangs.ForEach(s => sb.AppendLine(s));
            txtList.Text = sb.ToString();

            cmdOK.Click += new RoutedEventHandler(cmdOK_Click);
            txtList.TextChanged += (sx, ex) => { cmdOK.IsEnabled = true; };
		}


        void cmdOK_Click(object sender, RoutedEventArgs e)
        {
            Debug.WriteLine("cmdOK_Click");

            m_savedNlsLangs.Clear();
            string[] lines = txtList.Text.Split('\r');
            foreach (string line in lines)
            {
                Debug.WriteLine(string.Format("Line: {0}", line.Trim()));
                if (!string.IsNullOrWhiteSpace(line))
                    m_savedNlsLangs.AddItem(line.Trim());
            }
            foreach (var home in m_master.Homes)
                m_savedNlsLangs.AddItem(home.NlsLang);

            this.DialogResult = true;
            this.Close();
        }
	}
}